/*
 * @Author: your name
 * @Date: 2020-12-01 16:55:29
 * @LastEditTime: 2020-12-02 15:09:43
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \vue-element-admine:\hjimi\人脸\html\face-recognition\src\utils\encrypt.js
 */


import CryptoJS from 'crypto-js' 
// import md5 from 'js-md5'

/**
 * @description: AES加密
 */ 
// const key = CryptoJS.enc.Utf8.parse('1234123412ABCDEF') // 十六位十六进制数作为密钥
// const iv = CryptoJS.enc.Utf8.parse('ABCDEF1234123412') // 十六位十六进制数作为密钥偏移量
// 解密方法
function Decrypt (word, key) {
  let ckey = CryptoJS.enc.Utf8.parse(key) // 十六位十六进制数作为密钥
  // let encryptedHexStr = CryptoJS.enc.Hex.parse(word)
  // let srcs = CryptoJS.enc.Base64.stringify(encryptedHexStr)

  let decrypt = CryptoJS.AES.decrypt(word, ckey, {

    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  })
  let decryptedStr = decrypt.toString(CryptoJS.enc.Utf8)
//   console.log('decryptedStr', decryptedStr.toString())
  return decryptedStr.toString()
}

// 加密方法
function Encrypt (word, key) {
  let ckey = CryptoJS.enc.Utf8.parse(key)
  // let srcs = CryptoJS.enc.Utf8.parse(word)
  let encrypted = CryptoJS.AES.encrypt(word, ckey, {
    mode: CryptoJS.mode.ECB,
    padding: CryptoJS.pad.Pkcs7
  })
//   console.log('encrypted', encrypted.toString())
  return encrypted.toString()
}

// /**
//  * @description: MD5加密
//  */ 

//  导出2种加密方法
export default {
    Decrypt,
    Encrypt
  }

  //AES加密用法：
  // let key = this.login.password//设置密钥
  // let a = this.login.password = encrypt.Encrypt(this.login.password, key);//加密
  // let psd = encrypt.Decrypt(this.login.password, key);//解密
